package cn.ilikes.tools.nosql.jpa.unitls;

import java.util.List;

import javax.persistence.CascadeType;

import cn.ilikes.tools.nosql.jpa.metadatas.elements.EntityFields;

public class JPAUtils {

	public static EntityFields getForeignkeys(Class<?> targetEntity) {
		EntityFields FOREREIGN_ENTITY_FIELDS = new EntityFields(targetEntity.getSimpleName(), EntityFields.EntityFieldsType.RoreignKey);
		return FOREREIGN_ENTITY_FIELDS;
	}

	public static boolean containsCascade(List<CascadeType> cascades, CascadeType cascadeType_) {
		for (CascadeType cascadeType : cascades) {
			if (cascadeType.name().equals(cascadeType_.name()))
				return true;
		}
		return false;
	}

	public static boolean isRelation(EntityFields entityFields) {
		return (entityFields.getjPAField() != null && entityFields.getjPAField().isRelation());
	}

	/**
	 * 
	 * @param columnName
	 * @param index
	 *                  " jap @column Name = "family@qualifier"  or "
	 *                  family"   ;  index '@'  "
	 * @return
	 */
	public static String getfamily(String columnName, int index) {
		//		int index =columnName.indexOf(SysConfigs.hbase_column_family_qualifier) ;
		if (index != -1)
			return columnName.substring(0, index);
		return columnName;
	}

	public static String getQualifier(String columnName, int index) {
		//		int index =columnName.indexOf(SysConfigs.hbase_column_family_qualifier) ;
		if (index != -1)
			return columnName.substring(index + 1);
		return columnName;
	}
}
